<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>输血不良事件上报修改表</title>
  <link rel="stylesheet" href="../layui/css/layui.css">
  <script src="../layui/layui.js"></script>
  <style>
    td{
      padding-left: 10px;
      padding-bottom: 5px;
      padding-right: 20px;
      padding-top: 10px;
    }
  </style>
</head>
<body>
<button type="button" class="layui-btn"  id = “back” onclick="self.location = document.referrer;">返回</button>
<form class="layui-form" lay-filter="FormLoad">
  <table border="1px" width="100%" cellpadding="0">
    <tr >
      <td colspan="8" style="text-align: center; height: 50px"> <span style=" font-size: 20px">输血不良反应回报单</span> </td>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td colspan="2">
          时间：
        </td>
        <td colspan="6">
          <input type="text" name="report_date" id="report_date" placeholder="" class="layui-input">
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td colspan="1">
          受血患者姓名：
        </td>
        <td colspan="1">
          <input type="text" name="patient_name" placeholder="" class="layui-input">
        </td>
        <td colspan="1">
          性别
        </td>
        <td colspan="1">
          <select name="patient_sex" lay-verify="required">
            <option value=""></option>
            <option value="男">男</option>
            <option value="女">女</option>
          </select>
        </td>

        <td colspan="1">
          年龄
        </td>
        <td colspan="1">
          <input type="text" name="patient_age" placeholder="" class="layui-input">
        </td>
        <td colspan="1">
          血型
        </td>
        <td colspan="1">
          <input type="text" name="patient_blood_type" placeholder="" class="layui-input">
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">

        <td>
          住院门诊号：
        </td>
        <td colspan="1">
          <input type="text" name="patient_num" placeholder="" class="layui-input">
        </td>
        <td colspan="1">
          科别
        </td>
        <td colspan="2">
          <input type="text" name="reporter_department" placeholder="" class="layui-input">
        </td>
        <td colspan="1">
          床号
        </td>
        <td colspan="2">
          <input type="text" name="patient_bed_num" placeholder="" class="layui-input">
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">

        <td>
          输血史
        </td>
        <td colspan="1">
          <input type="radio" name="patient_transfusion_history" value="有" title="有">
          <input type="radio" name="patient_transfusion_history" value="无" title="无" >
        </td>
        <td colspan="1">
          妊娠史
        </td>
        <td colspan="2">
          <input type="radio" name="patient_pregnancy_history" value="孕" title="孕">
          <input type="radio" name="patient_pregnancy_history" value="产" title="产">
          <input type="radio" name="patient_pregnancy_history" value="无" title="无">
        </td>
        <td colspan="3"></td>
      </div>
    </tr>
    <td colspan="8" style="text-align: center; height: 30px"> <span style=" font-size: 12px">临床诊断</span> </td>
    <tr>
      <div class="layui-form-item">

        <td colspan="2">
          输血时患者是否处于全麻状态：
        </td>
        <td colspan="2">
          <input type="radio" name="patient_transfusion_status" value="是" title="是">
          <input type="radio" name="patient_transfusion_status" value="否" title="否" >
        </td>
        <td colspan="2">
          输血不良反应:
        </td>
        <td colspan="2">
          <input type="radio" name="patient_transfusion_bad_event" value="有" title="有">
          <input type="radio" name="patient_transfusion_bad_event" value="无" title="无" >
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td rowspan="2">
          输入血液：
        </td>

        <td colspan="1">
          血型：
        </td>
        <td colspan="2">
          <input type="text" name="patient_transfusion_blood_type" placeholder="" class="layui-input">
        </td>
        <td colspan="2"> 血肿：</td>
        <td colspan="2">
          <input type="text" name="patient_transfusion_blood_kind" placeholder="" class="layui-input">
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">

        <td colspan="1">
          输入量：
        </td>
        <td colspan="2">
          <input type="text" name="patient_transfusion_blood_amount" placeholder="" class="layui-input">
        </td>
        <td colspan="2"> 血袋信息码：</td>
        <td colspan="2">
          <input type="text" name="patient_transfusion_blood_num" placeholder="" class="layui-input">
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td colspan="1">
          献血者与受害者的关系：
        </td>
        <td colspan="7">
          <input type="radio" name="volunteer_relation_patient" value="一级亲属关系" title="一级亲属关系">
          <input type="radio" name="volunteer_relation_patient" value="二级亲属关系" title="二级亲属关系" >
          <input type="radio" name="volunteer_relation_patient" value="无亲属关系" title="无亲属关系" >
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td rowspan="4">
          输血不良反应情况
        </td>
        <td>
          发生时间：
        </td>
        <td colspan="3">
          <input type="radio" name="patient_transfusion_happen_time" value="输血前" title="输血前">
          <input type="radio" name="patient_transfusion_happen_time" value="输血后" title="输血后" >
        </td>
        <td colspan="1">
          转归：
        </td>
        <td colspan="2">
          <input type="radio" name="patient_transfusion_class" value="治愈" title="治愈">
          <input type="radio" name="patient_transfusion_class" value="死亡" title="死亡" >
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">

        <td>
          症状与体征：
        </td>
        <td colspan="6">
          <input type="checkbox" id="patient_transfusion_symptom" name="patient_transfusion_symptom" title="发热" value="发热" lay-skin="primary" >
          <input type="checkbox" id="patient_transfusion_symptom" name="patient_transfusion_symptom" title="发组" value="发组" lay-skin="primary">
          <input type="checkbox" id="patient_transfusion_symptom" name="patient_transfusion_symptom" title="腰背痛" value="腰背痛" lay-skin="primary" >
          <input type="checkbox" id="patient_transfusion_symptom" name="patient_transfusion_symptom" title="呼吸困难" value="呼吸困难" lay-skin="primary" >
          <input type="checkbox" id="patient_transfusion_symptom" name="patient_transfusion_symptom" title="两肺布满湿性落音" value="两肺布满湿性落音" lay-skin="primary">
          <input type="checkbox" id="patient_transfusion_symptom" name="patient_transfusion_symptom" title="黄痘" value="黄痘" lay-skin="primary" >
          <input type="checkbox" id="patient_transfusion_symptom" name="patient_transfusion_symptom" title="寒战" value="寒战" lay-skin="primary" >
          <input type="checkbox" id="patient_transfusion_symptom" name="patient_transfusion_symptom" title="荨麻疹" value="荨麻疹" lay-skin="primary">
          <input type="checkbox" id="patient_transfusion_symptom"  name="patient_transfusion_symptom" title="酱油性尿" value="酱油性尿" lay-skin="primary" >
          <input type="checkbox" id="patient_transfusion_symptom" name="patient_transfusion_symptom" title="咳大量血性泡沫样痰" value="咳大量血性泡沫样痰" lay-skin="primary" >
          <input type="checkbox" id="patient_transfusion_symptom" name="patient_transfusion_symptom" title="休克" value="休克" lay-skin="primary">
          <input type="checkbox" id="patient_transfusion_symptom" name="patient_transfusion_symptom" title="皮肤充血" value="皮肤充血" lay-skin="primary" >
          <input type="checkbox" id="patient_transfusion_symptom" name="patient_transfusion_symptom" title="劲静脉怒张" value="劲静脉怒张" lay-skin="primary" >
          <input type="checkbox" id="patient_transfusion_symptom" name="patient_transfusion_symptom" title="伤口渗血不止" value="伤口渗血不止" lay-skin="primary" >
          <input type="checkbox" id="patient_transfusion_symptom" name="patient_transfusion_symptom" title="其他" value="其他" lay-skin="primary" >
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td colspan="1">
          临床科室处理措施
        </td>
        <td colspan="6">
          <textarea name="clinical_dept_deal" style="height: 50px" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td colspan="1">
          诊断：
        </td>
        <td colspan="6">
          <input type="radio" name="bad_event_diagnose" value="发热反应" title="发热反应">
          <input type="radio" name="bad_event_diagnose" value="过敏反应" title="过敏反应" >
          <input type="radio" name="bad_event_diagnose" value="急性溶血反应" title="急性溶血反应" >
          <input type="radio" name="bad_event_diagnose" value="其他" title="其他" >
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td colspan="1">
          签名
        </td>
        <td colspan="1">
          护士
        </td>
        <td colspan="2">
          <input type="text" name="nurse_sign" placeholder="" class="layui-input">
        </td>
        <td colspan="1">
          经治医师：
        </td>
        <td colspan="1">
          <input type="text" name="treat_doctor_sign" placeholder="" class="layui-input">
        </td>
        <td colspan="1">
          临床科主任：
        </td>
        <td colspan="1">
          <input type="text" name="clinical_dept_header_sign" placeholder="" class="layui-input">
        </td>
      </div>
    </tr>
    <tr>
      <td colspan="3">
        输血科主任或负责人：
      </td>
      <td colspan="5">
        <input type="text" name="transfusion_dept_header_sign" placeholder="" class="layui-input">
      </td>
    </tr>
    <tr>        <td colspan="8">
      <span>备注：</span>
      <ol>
        <li>①输血不良反应回报登记制度是全面血液质量管理的一项重要内容，是输血反应跟踪调查信息统计的重要依据；</li>
        <li>②输血期间或输血后，若患者出现输血不良反应，临床科室应及时通知输血科，并及时填写此回报单报送输血科。</li>
      </ol>
    </td>
    </tr>
  </table>
  <div class="layui-form-item">
    <div class="layui-input-block" style="text-align: center; margin-top: 50px">
      <button class="layui-btn" lay-submit lay-filter="save1">暂存</button>
      <button class="layui-btn" lay-submit lay-filter="save2">提交</button>
    </div>
  </div>
</form>

</body>

<script>

  let str;
  layui.use(['laydate','jquery','form','layedit','layer','table','laytpl'], function() {
    let $ = layui.jquery;
    let form = layui.form;
    let laydate = layui.laydate;
    var layer = layui.layer;
    var router = layui.router();
    laydate.render({
      elem: '#reporter_know_time' //指定元素
      , type: 'date'
    });
    laydate.render({
      elem: '#event_happen_time' //指定元素
      , type: 'date'
    });

    function getQueryVariable(variable)
    {
      let query = window.location.search.substring(1);
      let vars = query.split("&");
      for (let i=0;i<vars.length;i++) {
        let pair = vars[i].split("=");
        if(pair[0] == variable){return pair[1];}
      }
      return(false);
    }

    form.render();
    // 获取地址的中的值
    let form_code=getQueryVariable("form_code");
    console.log(form_code);
    $.ajax({
      url: '/look?form_code=' + form_code,
      type: 'get',
      success: function (data) {
        //console.log(data);
        let jsonObj = eval('(' + data + ')'); //获得jsonObj对象
        //console.log(jsonObj);
        //渲染 上报人和上报人单位
        let json = {};
        for(let i = 0; i<jsonObj.data.length; i++) {
          if(jsonObj.data[i].property_en_name == "patient_transfusion_symptom") {
            var arr_symptom=jsonObj.data[i].detailed_data.split(',');
          } else {
            json[jsonObj.data[i].property_en_name] = jsonObj.data[i].detailed_data;
          }
        }
        //获取 多选框的总值

        console.log(arr_symptom);
        console.log(json);
        form.val("FormLoad",json);
        // var checkBoxArray = checkBox.split(",");
        // json["patient_transfusion_symptom"]
        //layui-unselect layui-form-checkbox layui-form-checked
        for(let j=0;j<arr_symptom.length-1;j++){
          // 多选框的都是check 为 true
          let unitTypeCheckbox = $("input[id='patient_transfusion_symptom']");
          for (var i = 0; i < unitTypeCheckbox.length; i++) {
            if (unitTypeCheckbox[i].title == arr_symptom[j]) {
              unitTypeCheckbox[i].value = arr_symptom[j];
              unitTypeCheckbox[i].checked = true;
            }
          }

          //原来的方法 --让样式选上
          $("input[name='patient_transfusion_symptom']").each(function(){
            if($(this).val()==arr_symptom[j]){
              console.log($(this));
              console.log($(this)[0].nextSibling);
              $($(this)[0].nextSibling).attr("class","layui-unselect layui-form-checkbox layui-form-checked");
            }
          })
        }

      }
    });

    form.on('submit(save1)', function (data) {
      layer.confirm('确定暂存吗？', {
        btn: ['确认', '取消'] //按钮
      }, function () {
        var arr_box = [];
        var str_checked="";
        $('input[type=checkbox]:checked').each(function(index) {
          arr_box.push($(this).val());
          str_checked+=arr_box[index];
          str_checked+=",";
        });
        let json = {
          "form_code": form_code,
          "report_date":data.field.report_date,
          "patient_name":data.field.patient_name,
          "patient_sex":data.field.patient_sex,
          "patient_age":data.field.patient_age,
          "patient_blood_type":data.field.patient_blood_type,
          "patient_num":data.field.patient_num,
          "reporter_department":data.field.reporter_department,
          "patient_bed_num":data.field.patient_bed_num,
          "patient_transfusion_history":data.field.patient_transfusion_history,
          "patient_transfusion_status":data.field.patient_transfusion_status,
          "patient_transfusion_bad_event":data.field.patient_transfusion_bad_event,
          "patient_transfusion_blood_type":data.field.patient_transfusion_blood_type,
          "patient_transfusion_blood_kind":data.field.patient_transfusion_blood_kind,
          "patient_transfusion_blood_amount":data.field.patient_transfusion_blood_amount,
          "patient_transfusion_blood_num":data.field.patient_transfusion_blood_num,
          "volunteer_relation_patient":data.field.volunteer_relation_patient,
          "patient_pregnancy_history":data.field.patient_pregnancy_history,
          "patient_transfusion_happen_time":data.field.patient_transfusion_happen_time,
          "patient_transfusion_class":data.field.patient_transfusion_class,
          "patient_transfusion_symptom":str_checked,
          "clinical_dept_deal":data.field.clinical_dept_deal,
          "bad_event_diagnose":data.field.bad_event_diagnose,
          "nurse_sign":data.field.nurse_sign,
          "treat_doctor_sign":data.field.treat_doctor_sign,
          "clinical_dept_header_sign":data.field.clinical_dept_header_sign,
          "transfusion_dept_header_sign":data.field.transfusion_dept_header_sign,
          "status":1 //暂存
        };

        $.ajax({
          url: '/event/event_update',
          type: "POST",
          data: json,
          success: function (index) {
            layer.msg("修改成功");
            self.location = document.referrer;
          }
        })

      }, function () {
        self.location = document.referrer;
      });
      return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });

    form.on('submit(save2)', function (data) {
      var arr_box = [];
      var str_checked="";
      $('input[type=checkbox]:checked').each(function(index) {
        arr_box.push($(this).val());
        str_checked+=arr_box[index];
        str_checked+=",";
      });
      layer.confirm('确定提交吗？', {
        btn: ['确认', '取消'] //按钮
      }, function () {
        let json = {
          "form_code": form_code,
          "report_date":data.field.report_date,
          "patient_name":data.field.patient_name,
          "patient_sex":data.field.patient_sex,
          "patient_age":data.field.patient_age,
          "patient_blood_type":data.field.patient_blood_type,
          "patient_num":data.field.patient_num,
          "reporter_department":data.field.reporter_department,
          "patient_bed_num":data.field.patient_bed_num,
          "patient_transfusion_history":data.field.patient_transfusion_history,
          "patient_transfusion_status":data.field.patient_transfusion_status,
          "patient_transfusion_bad_event":data.field.patient_transfusion_bad_event,
          "patient_transfusion_blood_type":data.field.patient_transfusion_blood_type,
          "patient_transfusion_blood_kind":data.field.patient_transfusion_blood_kind,
          "patient_transfusion_blood_amount":data.field.patient_transfusion_blood_amount,
          "patient_transfusion_blood_num":data.field.patient_transfusion_blood_num,
          "volunteer_relation_patient":data.field.volunteer_relation_patient,
          "patient_pregnancy_history":data.field.patient_pregnancy_history,
          "patient_transfusion_happen_time":data.field.patient_transfusion_happen_time,
          "patient_transfusion_class":data.field.patient_transfusion_class,
          "patient_transfusion_symptom":str_checked,
          "clinical_dept_deal":data.field.clinical_dept_deal,
          "bad_event_diagnose":data.field.bad_event_diagnose,
          "nurse_sign":data.field.nurse_sign,
          "treat_doctor_sign":data.field.treat_doctor_sign,
          "clinical_dept_header_sign":data.field.clinical_dept_header_sign,
          "transfusion_dept_header_sign":data.field.transfusion_dept_header_sign,
          "status":2 //递交
        };
        console.log(json);
        console.log("123");

        $.ajax({
          url: '/event/event_update',
          type: "POST",
          data: json,
          success: function (index) {
            layer.msg("修改成功");
            self.location = document.referrer;
          }
        })

      }, function () {
      });
      return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });

  })
</script>

</html>